module PcolorsHelper
  def nav_categories(categories = Pcate.parent_pcates)
    #    if cache_exist?('cate_nav')
    #      return
    #    else

    ret = ""

    for category in categories
      ret << "<dl>"  if !category.parent_id
      ret << display_category(category)
      ret << "</dl>"  if !category.parent_id
    end
    return ret
    #    end
  end

  private

  def display_category(category)
    if category.parent_id
      nav_html = "<dd>"
      nav_end ="</dd>"
    else
      nav_html = "<dt>"
      nav_end = "</dt>"
    end

    category_name = category.name
    nav_html << "<a href='/pcates/#{category.id}'>#{category_name}</a>"
    nav_html << nav_categories(category.children) if category.children.size > 0
    nav_html << nav_end
    return nav_html
  end
end
